package com.peanut.baby.mvp.feedback;

import android.app.Activity;

import com.peanut.baby.InitManager;
import com.peanut.baby.http.BaseObserver;
import com.peanut.baby.http.BaseScheduler;
import com.peanut.baby.http.RetrofitClient;
import com.peanut.baby.model.Feedback;

import cn.nekocode.rxlifecycle.RxLifecycle;
import io.reactivex.Observable;

/**
 * Created by anonymouslystudio on 2017/8/4.
 */

public class FeedbackPresenter implements FeedbackContract.Presenter{
    FeedbackContract.View view;
    private Activity activity;
    public FeedbackPresenter(FeedbackContract.View view,Activity activity){
        this.view = view;
        this.activity = activity;
    }



    @Override
    public void submitFeedback(String content, String contact) {
        Observable obs = RetrofitClient.getInstance().feedback(InitManager.getInstance().getUserId(),content,
                contact,InitManager.getInstance().getUser().userToken);
        obs.compose(BaseScheduler.<Feedback>compose())
                .compose(RxLifecycle.bind(activity).withObservable())
                .subscribe(new BaseObserver<Feedback>() {
            @Override
            protected void onHandleSuccess(Feedback o) {
                view.onSubmitFeedbackSuccess();
            }

            @Override
            protected void onHandleError(String code,String msg) {
                view.onRequestFailed(msg);
            }

        });
    }
}
